package cn.wangdian.erp.demo;

import cn.wangdian.erp.sdk.Client;
import cn.wangdian.erp.sdk.WdtErpException;
import cn.wangdian.erp.sdk.api.purchaseOrder.PurchaseOrderAPI;
import cn.wangdian.erp.sdk.api.purchaseOrder.dto.PurchaseOrderPendingResponse;
import cn.wangdian.erp.sdk.api.purchaseOrder.dto.PurchaseOrderUpdateInfoRequest;
import cn.wangdian.erp.sdk.impl.ApiFactory;
import cn.wangdian.erp.sdk.impl.DefaultClient;

import java.util.ArrayList;
import java.util.List;

public class PurchaseOrder
{
	public static void main(String[] args) throws WdtErpException
	{
		Client client = DefaultClient.get("wdterp30", "http://172.172.1.62:30000/", "xyx_api",
				"e8866c1681dacc9488a19c89991791b8:8f5800dab84b7a8d614e92cba739032c");
		PurchaseOrderAPI api = ApiFactory.get(client, PurchaseOrderAPI.class);

//		testUpdatePurchaseOrderInfo(api);
//		testPendingPurchaseOrder(api);
		cancelOrder(api);
	}

	private static void testUpdatePurchaseOrderInfo(PurchaseOrderAPI api) throws WdtErpException
	{
		PurchaseOrderUpdateInfoRequest request = new PurchaseOrderUpdateInfoRequest();
		request.setPurchaseNo("CG2305310003");
		request.setFlagName("推送失败");

		api.updatePurchaseInfo(request);
	}

	private static void testPendingPurchaseOrder(PurchaseOrderAPI api) throws WdtErpException
	{
		List<String> purchaseOrderNoList = new ArrayList<>();
		purchaseOrderNoList.add("CG2302130001");

		PurchaseOrderPendingResponse response = api.pending(purchaseOrderNoList);
		List<PurchaseOrderPendingResponse.ErrorInfo> errorInfoList = response.getErrorInfoList();
		if (errorInfoList.isEmpty())
		{
			System.out.println("success");
		}
		else
		{
			for (PurchaseOrderPendingResponse.ErrorInfo errorInfo : errorInfoList)
			{
				System.out.println("异常,采购单号: "+errorInfo.getOrderNo()+","+errorInfo.getMessage());
			}
		}
	}

	private static void cancelOrder(PurchaseOrderAPI api) throws WdtErpException
	{
		api.cancelOrder("CG2305230005");
	}
}
